package lab02.test23;

import java.util.Calendar;
import java.util.Scanner;

public class Test23 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("请输入你的生日的月份.");
        int birthdayMonth = s.nextInt() - 1;
        System.out.println("请输入你的生日的日期.");   //分别输入生日的月份和日期
        int birthdayDate = s.nextInt();

        Calendar birthday = Calendar.getInstance();
        birthday.set(Calendar.YEAR, 2017);
        birthday.set(Calendar.MONTH, birthdayMonth);
        birthday.set(Calendar.DATE, birthdayDate);   //设置生日的日期

        int year = birthday.get(Calendar.YEAR);
        int weekday = birthday.get(Calendar.DAY_OF_WEEK);    //用DAY_OF_WEEK方法得到生日是一周的第几天，1表示周日，2表示表示周一，依次类推。

        DayOfWeek dayOfWeek = new DayOfWeek();          //建立实例方法，得到生日是星期几
        dayOfWeek.dayOfWeek(weekday);

        System.out.print("现在的时间是.");              //得到现在的时间
        Calendar calendar = Calendar.getInstance();
        int nowYear = calendar.get(Calendar.YEAR);
        int nowMonth = calendar.get(Calendar.MONTH) + 1;
        int nowDate = calendar.get(Calendar.DATE);
        System.out.println(nowYear + "年" + nowMonth + "月" + nowDate + "日.");

        int nowDayOfYear = calendar.get(Calendar.DAY_OF_YEAR);      //现在的时间是一年的第几天
        int birthdayOfYear = birthday.get(Calendar.DAY_OF_YEAR);    //生日是一年的第几天
        int days = birthdayOfYear - nowDayOfYear  ;   //计算生日和现在相距好多天

        if (days < 0) {
            System.out.println("你的生日已过完。");
        } else if(days == 0){
            System.out.println("今天是你的生日，祝你生日快乐！");
        } else {
            System.out.println("距你的生日还有" + (days - 1) + "天");
        }
    }
}

